<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.12.4.js"></script>
</head>
<body>
Html
<input type="button" onclick="clickMe()" value="点我">
<input type="button" onclick="clickMe2()" value="点我2">
</body>

<script>
    var user = {id:1,username:"shine"};
    function clickMe(){
        $.ajax({
            url: "/test1",
            type: "post",
            //把js对象转换为json对象
            data:JSON.stringify(user),
            contentType: "application/json",
            success: function(data){
                //成功的回调函数
                alert("成功了");
                alert(data);
            },
            error: function(){
                //失败的回调函数
            }
        });
    }
    function clickMe2(){
        $.post("/test2","null",function (result) {
        if(result!=null){
            alert("成功了");
            alert(result);
        }
        })
    }

    /*function clickMe2(){
        $.ajax({
            url: "/test2",
            type: "post",
            success: function(data){
                //成功的回调函数
                alert("成功了");
                alert(data);
            },
            error: function(){
                //失败的回调函数
            }
        });
    }*/
</script>
</html>